package com.sean.stock.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sean.stock.entity.Stock;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface StockMapper extends BaseMapper<Stock> {
    public default void reduceByProductId(Long productId){
        LambdaUpdateWrapper<Stock> lambdaUpdateWrapper = new UpdateWrapper<Stock>().lambda();
        lambdaUpdateWrapper.eq(Stock::getProductId, productId);
        lambdaUpdateWrapper.setSql("count = count - 1");
        int update = update(new Stock(), lambdaUpdateWrapper);
    }
}
